//post json
package main

import (
    "bytes"
    "encoding/json"
    "io/ioutil"
    "log"
    "net/http"
)

type Cmd struct {

    AtAll bool `json:"atAll"`
    Content string `json:"content"`
	MessageType string `json:"messageType"`
}

func main() {
	data := &Cmd{}
	data.AtAll = false;
	data.Content = "test_Avensliu";
	data.MessageType = "text";

    url := "http://172.16.182.230:9999/dingtalk/rest/plugin/service/dingtalk/text"
    contentType := "application/json;charset=utf-8"

    b ,err := json.Marshal(data)
    if err != nil {
        log.Println("json format error:", err)
        return
	}
	log.Println(string(b))

    body := bytes.NewBuffer(b)

    resp, err := http.Post(url, contentType, body)
    if err != nil {
        log.Println("Post failed:", err)
        return
    }

    defer resp.Body.Close()

    content, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        log.Println("Read failed:", err)
        return
    }
    log.Println("content:", string(content))
}